package org.zoomdev.zoom.dao.handler;

import org.zoomdev.zoom.dao.SqlConfig;
import org.zoomdev.zoom.dao.entity.Entity;
import org.zoomdev.zoom.dao.entity.Field2ColumnMappingConfig;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public final class BeanResultSetHandler {


    public static Object fromResultSet(SqlConfig config, Entity entity, List<Field2ColumnMappingConfig> fields, ResultSet rs) throws SQLException {
        Object obj = entity.newInstance();
        for (int i = 0, c = fields.size(); i < c; ++i) {
            Field2ColumnMappingConfig field = fields.get(i);
            field.mapping(config, obj, rs, i + 1);
        }
        return obj;
    }
}
